package com.elinkway.infinitemovies.http.parser;

import com.elinkway.infinitemovies.bean.Lottery;
import com.elinkway.infinitemovies.bean.LotteryPopWindowInfo;
import com.elinkway.infinitemovies.utils.MoviesConstant;
import com.lvideo.http.exception.DataIsErrException;

import org.json.JSONObject;


public class LotteryParser extends LVideoMobileParser<Lottery> {

    @Override
    public Lottery parse(JSONObject data) throws Exception {
        Lottery ret = new Lottery();
        int status = data.getInt("status");
        ret.setStatus(status);
        if (status==200) {
            JSONObject object = data.getJSONObject("data");
            ret.setUrl(object.getString("url"));
            ret.setFlag(object.getInt("flag"));
            if(MoviesConstant.DEBUG){
            	ret.setFlag(Lottery.FLAG_ONGOING);
            }
            LotteryPopWindowInfo pwInfo = new LotteryPopWindowInfo();
            JSONObject pwObject = object.getJSONObject("windows");
            pwInfo.setFrequency(pwObject.getInt("frequency"));
            pwInfo.setMessage(pwObject.getString("msg"));
            pwInfo.setNegativeText(pwObject.getString("cancel"));
            pwInfo.setPositiveText(pwObject.getString("ok"));
            ret.setPopWinInfo(pwInfo);
        }
        else{
            throw new DataIsErrException("status "+status);
        }
        return ret;


    }

}
